var reviveCount = 5;
var mapIds = new Array();
var 准备地图 = 925020001;
var mapHead = 925070000;
var eventName = "副本_武陵道场";

function init() {}

function onMonsterDamaged() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance(eventName);
    for (var b = 0; b <= 80; b++) {
        mapIds.push(mapHead + b * 100)
    }
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully();
        d.killAllMonsters(true)
    }
    initProp("stage", 0);
    return c
}

function onPlayerRegistered(b, a) {
    a.setReviveCount(-100);
    var c = b.getMapInstance(925070000);
    a.changeMap(c, c.getPortal(0))
}

function onPlayerRevived(b, a) {
    return false
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    em.setProperty("kill", 0);
    em.setProperty("stage", (a - mapHead) / 100)
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onTimeOut(a) {
    if (a.getNumberProperty("pause") == 1) {
        return
    }
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onMonsterKilled(b, d) {
    if (player.getMap().getNumMonsters() == 0) {
        player.getAPI().fieldEffect_PlayFieldSound("Dojang/clear", 100);
        player.getAPI().fieldEffect_ScreenMsg("dojang/end/clear");
        player.getAPI().playerMessage(-1, "击败了对手, 计时器停止10秒. ");
        player.getMap().getReactorByName("door").forceHitReactor(player, 1);
        var a = Math.floor((player.getMapId() - 925070000) / 100);
        if (a == 10) {
            player.getAPI().finishAchievement(1303)
        } else {
            if (a == 20) {
                player.getAPI().finishAchievement(1304)
            } else {
                if (a == 30) {
                    player.getAPI().finishAchievement(1305)
                } else {
                    if (a == 40) {
                        player.getAPI().finishAchievement(1306)
                    } else {
                        if (a == 45) {
                            player.getAPI().finishAchievement(1307)
                        } else {
                            if (a == 50) {
                                player.getAPI().finishAchievement(1308)
                            } else {
                                if (a > 50 && a <= 56) {
                                    player.getAPI().gainSubAchievement(1309, a - 51)
                                } else {
                                    if (a > 56 && a < 63) {
                                        player.getAPI().gainSubAchievement(1310, a - 57)
                                    } else {
                                        if (a == 63) {
                                            player.getAPI().finishAchievement(1311)
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        b.setProperty("pause", 1);
        player.getAPI().setNumberForQuestInfo(3849, "time", b.getTimeLeft());
        b.stopEventTimer();
        player.getAPI().pauseTimer()
    } else {
        if (a > 30 && a < 40 && a != 33 && a != 36 && a != 39) {
            var e = em.getMapFactoryMap(mapHead + a * 100);
            var c = em.getMonster(9305600 + a - 1);
            b.getPlayers().forEach(function (f) {
                f.getMap().spawnMonsterWithEffect(c, 15, new java.awt.Point(randomNum(-200, 350), 7), false)
            })
        }
    }
    return 1
}

function onPlayerRevived(b, a) {
    return false
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    if (a) {
        b.getAPI().playerMessage(-1, "超过了允许在道场内挑战的时间。不得不离开了。");
        c.schedule("waitAndLeave", 2000)
    } else {
        c.disposeIfPlayerBelow(0, 准备地图);
        em.getProperties().clear();
        em.setProperty("state", 0);
        em.setProperty("leader", "true");
        c.unregisterPlayer(b)
    }
}

function waitAndLeave(a) {
    a.disposeIfPlayerBelow(isTimeout ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    a.unregisterPlayer(player)
}

function onItemPickedUp() {};